﻿#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <stdint.h>
#include <list>
using namespace std;
// TODO:  在此处引用程序需要的其他头文件
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/XyRyNet_CommHdr.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/NetEngine_StreamMedia/StreamMedia_RtmpClient/RtmpClient_Define.h"
#include "../../../../NetEngine_Windows/NetEngine_SourceCode/NetEngine_StreamMedia/StreamMedia_RtmpClient/RtmpClient_Error.h"

#pragma comment(lib,"Ws2_32.lib")
#pragma comment(lib,"../../../../NetEngine_Windows/NetEngine_SourceCode/Debug/StreamMedia_RtmpClient.lib")

FILE* pSt_File;
int fread_user(LPVOID lParam, uint8_t* puszMsgBuffer, int nSize)
{
	printf("%d\n", nSize);
	int nRet = fread(puszMsgBuffer, 1, nSize, pSt_File);
	if (nRet <= 0)
	{
		return -1;
	}
	return nRet;
}

int main()
{
	WSADATA st_WSAData;
	WSAStartup(MAKEWORD(2, 2), &st_WSAData);
	XNETHANDLE xhStream = 0;
	LPCTSTR lpszUrl = _T("rtmp://www.xyry.org:1935/live/qyt");
	LPCTSTR lpszFile = _T("E:\\netengineapp\\NetEngine_WINApps\\Debug\\1080P.264");
	//LPCTSTR lpszFile = _T("E:\\netengineapp\\NetEngine_WINApps\\Debug\\test.aac");

	BOOL bMemory = TRUE;

	if (bMemory)
	{
		pSt_File = _tfopen(lpszFile, "rb");
		if (NULL == pSt_File)
		{
			printf("_tfopen:%d\n", GetLastError());
			return -1;
		}
		if (!RtmpClient_FilePush_Push(&xhStream, lpszFile, lpszUrl, fread_user, NULL))
		{
			printf("RtmpClient_FilePush_Push:%lX\n", RtmpClient_GetLastError());
			return -1;
		}
	}
	else
	{
		if (!RtmpClient_FilePush_Push(&xhStream, lpszFile, lpszUrl))
		{
			printf("RtmpClient_FilePush_Push:%lX\n", RtmpClient_GetLastError());
			return -1;
		}
	}

	BOOL bIsPush = TRUE;
	while (bIsPush)
	{
		RtmpClient_FilePush_GetStatus(xhStream, &bIsPush);

		Sleep(1000);
	}
	RtmpClient_FilePush_Close(xhStream);
	WSACleanup();
	return 0;
}